home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-25 | 6.5 KB | 230 lines | [TEXT/Moml] |
- (* dirdiff.sml *)
- (* 25Jul97 e *)
-
- load "FileSys";
- load "Path";
- load "Time";
- load "Date";
- load "String";
-
- (* requires copyrelease.sml *)
- (*
- load "Process";
- val home =
- case Process.getEnv "PATH_TRANSLATED" of
- SOME n => Path.dir n
- | NONE => ":"
- ;
- use (home ^ "e_SML:copyrelease.sml");
- *)
-
- open FileSys
-
- datatype diff = SAME
- | ADDED of string
- | DELETED of string
- | TIME of string * Time.time * Time.time
- | SIZE of string * int * int
- | ERROR of string
-
- fun dif_files old new =
- if access (old, [])
- then if access (new, [])
- then if modTime old = modTime new
- then if fileSize old = fileSize new
- then SAME
- else SIZE (old, fileSize old, fileSize new)
- else TIME (old, modTime old, modTime new)
- else DELETED old
- else ERROR old
-
- fun dif_dirs old new =
- let val dir = openDir old
- val _ = chDir old
- val result = ref []
- fun comp_file fname =
- let val {base, ext} = Path.splitBaseExt fname
- val tname = Path.joinDirFile {dir = new, file = fname }
- in if isDir fname
- then () (* do nested dirs? *)
- else if (case ext of SOME "ui" => true
- | SOME "uo" => true
- | _ => false)
- then ()
- else case dif_files fname tname of
- SAME => ()
- | x => result := x :: (!result)
- end
- fun comp "" = ()
- | comp f = ( comp_file f ; comp (readDir dir) )
- in
- let val _ = comp (readDir dir)
- in closeDir dir; !result
- end
- handle exn as OS.SysErr (msg, _) => (closeDir dir; raise exn)
- end
- ;
-
- fun dib_files old new =
- if access (old, [])
- then if access (new, [])
- then SAME (* well, dif already checked so we needn't bother *)
- else ADDED old
- else ERROR old
-
- fun dib_dirs old new resf =
- let val dir = openDir old
- val _ = chDir old
- val result = ref resf
- fun comp_file fname =
- let val {base, ext} = Path.splitBaseExt fname
- val tname = Path.joinDirFile {dir = new, file = fname }
- in if isDir fname
- then () (* do nested dirs? *)
- else if (case ext of SOME "ui" => true
- | SOME "uo" => true
- | _ => false)
- then ()
- else case dib_files fname tname of
- SAME => ()
- | x => result := x :: (!result)
- end
- fun comp "" = ()
- | comp f = ( comp_file f ; comp (readDir dir) )
- in
- let val _ = comp (readDir dir)
- in closeDir dir; !result
- end
- handle exn as OS.SysErr (msg, _) => (closeDir dir; raise exn)
- end
- ;
-
- fun diff_dirs old new = dib_dirs new old (dif_dirs old new);
-
- fun show_diffs difs =
- let fun print_sps x =
- let val z = (14 - (String.size x))
- in
- if z < 0
- then print " "
- else print (String.substring (" ",0,z))
- end
- fun sdif SAME = ()
- | sdif (ADDED s) =
- (print "Added: "; print s; print "\n")
- | sdif (DELETED s) =
- (print "Removed: "; print s; print "\n")
- | sdif (TIME (s,t1,t2)) =
- ((if Time.> (t2, t1)
- then print "Changed: "
- else print "Revertd: ");
- print s; print_sps s;
- print (Date.toString(Date.fromTime(t1))); print " - " ;
- print (Date.toString(Date.fromTime(t2))); print "\n")
- | sdif (SIZE (s,z1,z2)) =
- (print "SizeErr: "; print s; print "\n")
- | sdif (ERROR s) =
- (print "ProbErr: "; print s; print "\n")
- fun sdifs [] = ()
- | sdifs (d::r) = (sdif d; sdifs r)
- in
- sdifs difs
- end
- ;
-
- (* requires copyrelease.sml *)
-
- fun copy_diffs difs new tgt =
- let val () = ensure_dir tgt
- fun copy_file name =
- let val fname = Path.joinDirFile {dir = new, file = name }
- val tname = Path.joinDirFile {dir = tgt, file = name }
- in
- copy_txt_file fname tname
- end
- fun sdif SAME = ()
- | sdif (ADDED s) = copy_file s
- | sdif (DELETED s) = ()
- | sdif (TIME (s,t1,t2)) = copy_file s
- | sdif (SIZE (s,z1,z2)) = copy_file s
- | sdif (ERROR s) = ()
- fun sdifs [] = ()
- | sdifs (d::r) = (sdif d; sdifs r)
- in
- sdifs difs
- end
- ;
-
- fun compare_copied_diffs difs new tgt =
- let fun cmp_file name =
- let val fname = Path.joinDirFile {dir = new, file = name }
- val tname = Path.joinDirFile {dir = tgt, file = name }
- in
- compare_files fname tname
- end
- fun sdif SAME = ()
- | sdif (ADDED s) = cmp_file s
- | sdif (DELETED s) = ()
- | sdif (TIME (s,t1,t2)) = cmp_file s
- | sdif (SIZE (s,z1,z2)) = cmp_file s
- | sdif (ERROR s) = ()
- fun sdifs [] = ()
- | sdifs (d::r) = (sdif d; sdifs r)
- in
- sdifs difs
- end
- ;
-
- (*
-
- val homeold = (home ^ ":releases:142:mosml:src:");
- val homenew = (home ^ "src:");
-
- val hometgt = (home ^ ":releases:difs142:");
- ensure_dir hometgt;
-
- val difs =
- diff_dirs (homeold ^ "compiler") (homenew ^ "compiler");
- show_diffs difs;
- copy_diffs difs (homenew ^ "compiler") (hometgt ^ "compiler:");
- compare_copied_diffs difs (homenew ^ "compiler") (hometgt ^ "compiler:");
-
- val difs =
- diff_dirs (homeold ^ "mosmllib") (homenew ^ "mosmllib");
- show_diffs difs;
- copy_diffs difs (homenew ^ "mosmllib") (hometgt ^ "mosmllib:");
- compare_copied_diffs difs (homenew ^ "mosmllib") (hometgt ^ "mosmllib:");
-
- val difs =
- diff_dirs (homeold ^ "runtime") (homenew ^ "!runtime");
- show_diffs difs;
- copy_diffs difs (homenew ^ "!runtime") (hometgt ^ "runtime:");
- compare_copied_diffs difs (homenew ^ "!runtime") (hometgt ^ "runtime:");
-
- val difs =
- diff_dirs (homeold ^ "lex") (homenew ^ "lex");
- show_diffs difs;
- copy_diffs difs (homenew ^ "lex") (hometgt ^ "lex:");
- compare_copied_diffs difs (homenew ^ "lex") (hometgt ^ "lex:");
-
- val difs =
- diff_dirs (homeold ^ "toolssrc") (homenew ^ "toolssrc");
- show_diffs difs;
- copy_diffs difs (homenew ^ "toolssrc") (hometgt ^ "toolssrc:");
- compare_copied_diffs difs (homenew ^ "toolssrc") (hometgt ^ "toolssrc:");
-
- (* move testbadl temporarily... *)
-
- val difs =
- diff_dirs (homeold ^ "mosmllib:test") (homenew ^ "mosmllib:test");
- show_diffs difs;
- copy_diffs difs (homenew ^ "mosmllib:test") (hometgt ^ "mosmllib:test:");
- compare_copied_diffs difs (homenew ^ "mosmllib:test") (hometgt ^ "mosmllib:test:");
-
- val difs =
- diff_dirs (homeold ^ "mosmlyac") (homenew ^ "mosmlyac");
- show_diffs difs;
- (* copy by hand *)
-
- *)
-